/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ar.com.siglo21.ppo.persistence.dao;

import ar.com.siglo21.ppo.model.Genero;
import ar.com.siglo21.ppo.persistence.MySQLConnection;
import ar.com.siglo21.ppo.util.TrabajoIntegradorException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class GeneroDAOImpl implements GeneroDAO{

    @Override
    public void agregar(Genero object) throws TrabajoIntegradorException, SQLException {
       String sql="Insert into genero(descripcion) values ('"+object.getDescripcion()+"')";
       MySQLConnection.getDbCon().insertORDeleteORUpdate(sql);
    }

    @Override
    public boolean existe(Genero object) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void eliminar(Genero object) throws TrabajoIntegradorException, SQLException {
       
      String sql ="DELETE FROM GENERO where id="+object.getId();
      MySQLConnection.getDbCon().insertORDeleteORUpdate(sql);
        
    }

    @Override
    public Genero leer(int id) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    /**
     *
     * @return
     * @throws SQLException
     * @throws TrabajoIntegradorException
     */
    @Override
    public List<Genero> listarGeneros() throws SQLException, TrabajoIntegradorException {
       
        Genero genero;
        String sql ="SELECT * FROM genero";
        List<Genero> listaGeneros = new ArrayList();
        ResultSet resulset = MySQLConnection.getDbCon().query(sql);
        
        while(resulset.next()){
            genero = new Genero();
            genero.setId(resulset.getInt(1));
            genero.setDescripcion(resulset.getString(2));
            listaGeneros.add(genero);
        }
        
        return listaGeneros;
    }    

    @Override
    public void actualizar(Genero object) throws TrabajoIntegradorException, SQLException {
       String sql="UPDATE GENERO SET descripcion='"+object.getDescripcion()+"' where id="+object.getId();
       MySQLConnection.getDbCon().insertORDeleteORUpdate(sql);
       
    }

    
}

   
    
    
    
